#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

const int _buf_size = 5000000;

int main(int argc, char *argv[])
{
	srand(123456789);
	if (argc < 3) {
		printf("%s: not enough parameters!\n", argv[0]);
		exit(1);
	}

	FILE *f = fopen(argv[1], "w");
	if (f == NULL) {
		printf("%s: cannot write %s!\n", argv[0], argv[1]);
		exit(1);
	}
	setvbuf(f, NULL, _IOFBF, _buf_size);
	long long cnt = 0;
	for (int i = 2; i < argc; ++i) {
		FILE *inf = fopen(argv[i], "r");
		if (inf == NULL) {
			printf("%s: cannot read %s!\n", argv[0], argv[i]);
			exit(1);
		}
		while (1) {
			char c = fgetc(inf);
			if (c == EOF) break;
			fputc(c, f);
			++cnt;
			if (cnt % 1000000 == 0) {
				double mb = cnt / 1024./1024.;
				printf("%s: processing %s... ", argv[0], argv[i]);
				if (mb > 1000.)
					printf("[copied %.1lf GB]\n", mb / 1024.);
				else
					printf("[copied %.1lf MB]\n", mb);
			}
		}
		fclose(inf);
	}
	fclose(f);

	printf("%s: done.\n", argv[0]);

	return 0;
}

